﻿package com.flashwiitanks
{
	import flash.display.*;
	import flash.events.*;
	
	public class EnemyTank extends MovieClip
	{
		//the index of the tank in the array of enemy tanks
		var enemyIndex:int;
		
		//number of bullets
		var clip:Number = 1;		
		
		//var turn speed
		var turnSpeed:Number = 5;
		var main:MovieClip;
		
		public function EnemyTank(index:int) {
			//set the index of the tank in the enemyTanks array
			enemyIndex = index;
			
			//when enemy is added to the stage
			this.addEventListener(Event.ADDED, initialize)
		}
		
		public function initialize(event:Event):void {
			//get the main stage
			main = MovieClip(this.parent.parent);
		}

		public function shootBullet(event:MouseEvent):void {
			if(clip > 0) {
				var bullet:MovieClip = new Bullet(this);
				this.parent.addChild(bullet);
				clip--;
			}
		}		
		
		//when a bullet is destroyed, the clip is increased to allow another bullet to fire
		public function increaseClip():void {
			clip++;
		}
		
		//if this tank is getting hit with a bullet, it should be killed
		public function kill():void {
			main.removeEnemyTank(this);
		}
	}
}